﻿using Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DearInformation.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Login(User user)
        {

            UserServer server = new UserServer();
            string id = user.Uid.ToString();

            User u = server.GetUserById(id);
            if (u != null)
            {
                List<User> list = server.GetAllUser();
                User ou = new User();
                if (list.Count <= 1)
                {
                    ou = null;
                }
                else
                {
                    ou = list.Where(p => p.Uid != id).ToList()[0];
                }
                Session["user"] = u;
                Session["otheruser"] = ou;
                return RedirectToAction("UserList", "User");
            }
            return RedirectToAction("Index", "Home");
        }
    }
}
